package com.ruoyi.consumer.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.consumer.domain.CFillingFacilit;
import com.ruoyi.consumer.service.ICFillingFacilitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * 加注机Controller
 * 
 * @author YFENTEST
 * @date 2023-11-28
 */
@RestController
@RequestMapping("/consumer/facilit")
public class CFillingFacilitController extends BaseController
{
    @Autowired
    private ICFillingFacilitService cFillingFacilitService;

    /**
     * 查询加注机列表
     */
//    @PreAuthorize("@ss.hasPermi('consumer:facilit:list')")
    @GetMapping("/list")
    public TableDataInfo list(CFillingFacilit cFillingFacilit)
    {
        startPage();
        List<CFillingFacilit> list = cFillingFacilitService.selectCFillingFacilitList(cFillingFacilit);
        return getDataTable(list);
    }

    /**
     * 首页加注机列表
     * @param cFillingFacilit
     * @return
     */
    @GetMapping("/get-list")
    public TableDataInfo Getlist(CFillingFacilit cFillingFacilit)
    {
        startPage();
        List<CFillingFacilit> list = cFillingFacilitService.selectCFillingFacilitList(cFillingFacilit);
        List<CFillingFacilit> results = new ArrayList<>();
        for (CFillingFacilit facilit : list) {
            if (facilit.getStationId() == null || facilit.getStationId() == 0 ) {
                continue;
            } else {
                results.add(facilit);
            }
        }
        return getDataTable(results);
    }

    /**
     * 导出加注机列表
     */
//    @PreAuthorize("@ss.hasPermi('consumer:facilit:export')")
    @Log(title = "加注机", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CFillingFacilit cFillingFacilit)
    {
        List<CFillingFacilit> list = cFillingFacilitService.selectCFillingFacilitList(cFillingFacilit);
        ExcelUtil<CFillingFacilit> util = new ExcelUtil<CFillingFacilit>(CFillingFacilit.class);
        util.exportExcel(response, list, "加注机数据");
    }

    /**
     * 获取加注机详细信息
     */
//    @PreAuthorize("@ss.hasPermi('consumer:facilit:query')")
    @GetMapping(value = "/{facilitId}")
    public AjaxResult getInfo(@PathVariable("facilitId") Integer facilitId)
    {
        return success(cFillingFacilitService.selectCFillingFacilitByFacilitId(facilitId));
    }

    /**
     * 新增加注机
     */
//    @PreAuthorize("@ss.hasPermi('consumer:facilit:add')")
    @Log(title = "加注机", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CFillingFacilit cFillingFacilit)
    {
        return toAjax(cFillingFacilitService.insertCFillingFacilit(cFillingFacilit));
    }

    /**
     * 修改加注机
     */
//    @PreAuthorize("@ss.hasPermi('consumer:facilit:edit')")
    @Log(title = "加注机", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CFillingFacilit cFillingFacilit)
    {
        return toAjax(cFillingFacilitService.updateCFillingFacilit(cFillingFacilit));
    }

    /**
     * 删除加注机
     */
//    @PreAuthorize("@ss.hasPermi('consumer:facilit:remove')")
    @Log(title = "加注机", businessType = BusinessType.DELETE)
	@DeleteMapping("/{facilitIds}")
    public AjaxResult remove(@PathVariable Integer[] facilitIds)
    {
        return toAjax(cFillingFacilitService.deleteCFillingFacilitByFacilitIds(facilitIds));
    }
}
